package dyyx;

import java.util.Date;
import java.util.Set;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Tuple;

public class ZsetTest {
	

	
	
	
	public static void main(String[] args) throws Exception {
		
		System.out.println("hello,ZsetTest");
		Jedis jedis = new Jedis("127.0.0.1");
		System.out.println(jedis.info());
		

		System.out.println("使用时间戳负数作为score");
		
		String key = "zsetkey";
		Date time = new Date();
		int size = 5;
		double score = 0 - time.getTime();
		jedis.zadd(key, score, time+"");
		
		Long zcard = jedis.zcard(key);
		System.out.println("zcard="+zcard);

		Long zcount = jedis.zcount(key,  Long.MIN_VALUE, Long.MAX_VALUE);
		System.out.println("zcount="+zcount);

		
		Set<Tuple> zsets = jedis.zrangeByScoreWithScores(key,  Long.MIN_VALUE, Long.MAX_VALUE,0,size);
		
		System.out.println(zsets);
		
		int start = size;
		int stop = Integer.MAX_VALUE;
		jedis.zremrangeByRank(key, start, stop);
		
		
		System.out.println("使用时间戳作为score");
		
		key = "zsetkey2";
		score = time.getTime();
		jedis.zadd(key, score, time+"");
		
		zcard = jedis.zcard(key);
		System.out.println("zcard="+zcard);

		zcount = jedis.zcount(key,  0, Long.MAX_VALUE);
		System.out.println("zcount="+zcount);
	
		zsets = jedis.zrangeByScoreWithScores(key,  0, Long.MAX_VALUE,0,size);
		
		System.out.println(zsets);
		
		start = 0 - size - 9;
		stop = 0 - size;
		jedis.zremrangeByRank(key, start, stop);
		
		jedis.close();
		
	
	}	
	
}
